package main

import "fmt"

func printSlice(x []int) {
	fmt.Printf("len = %d cap = %d slice = %d\n", len(x), cap(x), x)
}

func main() {
	// len()获取长度，cap()测量切片最长可以达到多少
	/*var number = make([]int, 3, 5)
	printSlice(number)*/

	/*var number []int
	printSlice(number)
	// nil等价于C语言中的NULL
	if (number == nil) {
		fmt.Printf("切片是空的\n")
	}*/

	/*// 创建切片
	number := []int{0, 1, 2, 3, 4, 5, 6, 7, 8}
	printSlice(number)
	// 打印原始切片
	fmt.Println("number == ", number)
	// 打印子切片从下标1(包含)到下标4(不包含)
	fmt.Println("number[1:4] == ", number[1:4])
	// 默认下限为0
	fmt.Println("number[:3] == ", number[:3])
	// 默认下限为len(s)
	fmt.Println("number[4:] == ", number[4:])
	number1 := make([]int, 0, 5)
	printSlice(number1)
	// 打印子切片从下标0(包含)到下标2(不包含)
	number2 := number[:2]
	printSlice(number2)
	// 打印子切片从下标2(包含)到下标5(不包含)
	number3 := number[2:5]
	printSlice(number3)*/

	var number []int
	printSlice(number)
	// 允许追加空切片
	number = append(number, 0)
	printSlice(number)
	// 向切片添加一个元素
	number = append(number, 1)
	printSlice(number)
	// 同时添加多个元素
	number = append(number, 2, 3, 4)
	printSlice(number)
	// 创建切片number1是之前切片的两倍容量
	number1 := make([]int, len(number), (cap(number)) * 2)
	// 拷贝number的内容到number1
	copy(number1, number)
	printSlice(number1)
}
